from fastapi import APIRouter
from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html

from app.config import settings

router = APIRouter()


@router.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        title=settings.TITLE + " - Swagger UI",
        openapi_url="/openapi.json",
        swagger_favicon_url="/static/docs/swagger.png",
        swagger_js_url="/static/docs/swagger-ui-bundle.js",
        swagger_css_url="/static/docs/swagger-ui.css",
        swagger_ui_parameters={
            "docExpansion": "none",  # 设置所有 tags 默认折叠
            "persistAuthorization": True,  # 保持授权状态
            "oauth2RedirectUrl": "http://localhost:8000/docs",  # 用户登录并授权后，服务器重定向回 http://localhost:8000/docs
        },
    )


@router.get("/redoc", include_in_schema=False)
async def redoc_html():
    return get_redoc_html(
        openapi_url="/openapi.json",
        title=settings.TITLE + " - ReDoc",
        redoc_js_url="/static/docs/redoc.standalone.js",
    )
